package com.example.idlefish.MyAccount.contract

import android.app.*
import android.content.*
import androidx.activity.result.contract.*
import com.example.idlefish.MyAccount.activity.*
import com.example.idlefish.MyAccount.pojo.*

class LoginContract:  ActivityResultContract<Long, UserHomepageInfo?>() {
    override fun createIntent(context: Context, input: Long): Intent {
        return Intent(context, LoginActivity::class.java).apply {
            putExtra("id", input)
        }
    }

    override fun parseResult(resultCode: Int, intent: Intent?): UserHomepageInfo? {
        if(intent == null) {
            return null
        }
        val data = CommonUtil.getSerializable(intent, "userInfo", UserHomepageInfo::class.java)
//        println("登录contract: $data")
        if(resultCode == Activity.RESULT_OK){
            return data
        }
        return null
    }
}
